//---------------------------------------------------------------------------- // File: C3DFont.h [v2.0] // Class: C3DFont -- A common font that can be used to display text in the 3d world. // Type: 3D Object // Author: Ken Anderson // Date: 2/6/06 // OS dependant: NA // Desc: A class specifically designed to display text in the 3d world. // Version: // 1.0[4/19/05] -- Init. // 1.1[11/27/05] -- Destroy member added to the class. // 2.0[2/6/06] -- Updated to use indices. // // Required headers: // 1) C3DVertices.h -- A link to the vertices required to create the quads. // 2) C3DTextures.h -- A link to the texture to use as a text map. // 3) C3DIndices.h -- A link to the indices to reduce the amount of vertices per char. //---------------------------------------------------------------------------- #ifndef __C3DFont__ #define __C3DFont__ /////////////// // INCLUDES // /////////////// #include "OS_Global.h" #include "Common.h" #include "C3DVertices.h" #include "C3DTextures.h" #include "C3DIndices.h" ////////////////// // DEFINITIONS // ////////////////// #define C3DFONT_MAX_CHARS 80*25 //80 characters * 25 lines ////////////////////////////// // FUNCTION DEFINED STRUCT // ////////////////////////////// typedef struct C3DFONT_PROPERTIES { int nResolution; //The resolution is set by the size of the image. int nFontSize; //The point size of the font to use. string sFontName; //A pointer to a string that contains the font name to use. bool bBold; //The bold property. bool bItalic; //The Italic property. } C3DFONTPROP, *PC3DFONTPROP; class C3DFont { public: //Constructor & Destructor C3DFont(); C3DFont(const C3DFont& font); /////////////////////////////////////////////////////////////////////////////////////////////////////// // Name: Destructor // Date: 4/19/05 // Type: Common 3D Object. // Desc: Cleans up & destroys member variables. // Parameters: None // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// ~C3DFont(){Cleanup();} /////////////////////////////////////////////////////////////////////////////////////////////////////// // Name: Destroy // Date: 4/19/05 // Type: Common 3D Object. // Desc: Deallocates and cleans up all memory and resources used by the font class. // Parameters: None // Return Value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// inline void Destroy(){Cleanup();} /////////////////////////////////////////////////////////////////////////////////////////////////////// // Name: Clear // Date: 5/22/05 // Type: Common 3D Object. // Desc: Reset the overlay/object's display to zero blocks. // Parameters: None // Return value: None ////////////////////////////////////////////////////////////////////////////////////////////////////// inline void Clear(){m_dwLastBlock = 0;} //Quad controllers. C3DERR Create(PC3DFONTPROP pfp, float fWidth=0.0f, float fHeight=0.0f, bool bFont2D = true, bool bShadow = false, int nNumChars=C3DFONT_MAX_CHARS); //Functionality. //**TO IMPLEMENT**// //void Print(cstr str, float x=0.0f, float y=0.0f, float z=0.0f); void Print(string& s, float x=0.0f, float y=0.0f, float z=0.0f, Dword dwColor=0xFFFFFFFF); void Print(unchar ch, float x=0.0f, float y=0.0f, float z=0.0f, Dword dwColor=0xFFFFFFFF); C3DERR Render(); //Tools float GetCharHeight(unchar ch); float GetCharWidth(unchar ch); float GetMaxHeight(); float GetHeight(string& s); float GetWidth(string& s); //Return Text properties. inline string GetFontName(){return m_sFontName;} inline int GetFontSize(){return m_nFontSize;} inline bool IsBold(){return m_bBold;} inline bool IsItalic(){return m_bItalic;} //Adjust Text properties. C3DERR SetFont(string& sFontName, int nFontSize, bool bBold, bool bItalic); void SetPosition(float x, float y, float z); //Return Fonts's various behaviors. inline int GetMaxCharacters(){return m_dwMaxChars;} inline int GetResolution(){return m_nResolution;} inline float GetTransformed(){return m_bTransformed;} //**********FUTURE IMPLEMENTATION***********// //Adjust the Font's behavior //These features will require the vertices to be destroyed //and recreated in order to create the specific level of divisions. // //void SetMaxCharacters(int nMaxChars); //**********FUTURE IMPLEMENTATION***********// private: void Cleanup(); C3DERR GenerateTexture(); C3DERR GenerateVertices(); bool MapCharToBlock(unchar ch, float x, float y, float z, Dword dwColor, Dword dwIndex); //Font Map behavior. PFRect m_pfrTexCoord; //An array of coordinates for each character block. int m_nNumChars; //Number of characters created by the ImageMap //C3DFont Dimensions float m_fX, m_fY, m_fZ; //X, Y & Z offsets. float m_fWidth, m_fHeight; //Bounding Dimensions. //C3DFont's behavior. bool m_bTransformed; //Toggles whether the vertices should be transformed or not. float m_fLineHeight; //The height of the newline. float m_fScale; //The scale of the font. int m_nResolution; //The resolution of the image map used. Dword m_dwMaxChars; //The maximum characters supported. //Font properties. bool m_bBold; //Bold property. bool m_bItalic; //Italic property. bool m_bShadow; //Shadow property. float m_fShadowOffset; //Offset of the shadow. int m_nFontSize; //Size of the font. string m_sFontName; //Name of the font. //Cache objects. Dword m_dwLastBlock; //3D Objects. C3DVertices* m_pfVerts; C3DIndices* m_pIds; C3DTextures* m_pTexture; }; #endif